//
//  AXNzscNztjSecondVC.m
//  AnXin100
//
//  Created by 天质弘耕 on 2018/11/6.
//  Copyright © 2018 tzhg. All rights reserved.
//

#import "AXNzscNztjSecondVC.h"
#import "UIView+SDAutoLayout.h"
#import "ZXCategories.h"
#import "Header.h"
#import "UITableView+SDAutoTableViewCellHeight.h"
#import "AXNzscNztjSecondCell.h"
#import "AXNzscNztjSecondModel.h"
#import "UIViewController+HBD.h"
#import "LLSearchViewController.h"


@interface AXNzscNztjSecondVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) NSMutableArray<AXNzscNztjSecondModel *>  *modelsArray;
@property (nonatomic ,strong) UITableView *tableView;
@property (nonatomic ,strong) UIView *headView;
/** 假图片数据 */
@property (nonatomic, strong) NSArray<NSString *> *imageNames;
@property (nonatomic, strong) NSArray<NSString *> *titleNames;
@property (nonatomic, strong) NSArray<NSString *> *priceNames;
/** 搜索按钮 */
@property (nonatomic ,strong) UIButton *searchButton;
@property (nonatomic , assign) NSInteger requstIndex;

@end

@implementation AXNzscNztjSecondVC

- (void)viewDidLoad {
    [self initData];
    [super viewDidLoad];
    [self creatView];
    [self setlayout];
    [self setupNavigationItems];
    self.hbd_barTintColor = [UIColor whiteColor];
    self.hbd_barShadowHidden = YES;
}

- (void)creatView {
    
    self.tableView = [[UITableView alloc]init];
    /** 去掉cell线 */
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[AXNzscNztjSecondCell class] forCellReuseIdentifier:[AXNzscNztjSecondCell reuseID]];
    [self.view addSubview:self.tableView];
    
    
    
}

- (void)initData {
    self.titleNames = @[@"【农家特产】大蒜5斤/10斤 干蒜头大蒜头蒜子批发农产品产地直发1",@"【农家特产】大蒜5斤/10斤 干蒜头大蒜头蒜子批发农产品产地直发2",@"【农家特产】大蒜5斤/10斤 干蒜头大蒜头蒜子批发农产品产地直发3",@"【农家特产】大蒜5斤/10斤 干蒜头大蒜头蒜子批发农产品产地直发4",@"【农家特产】大蒜5斤/10斤 干蒜头大蒜头蒜子批发农产品产地直发5",@"【农家特产】大蒜5斤/10斤 干蒜头大蒜头蒜子批发农产品产地直发6",@"【农家特产】大蒜5斤/10斤 干蒜头大蒜头蒜子批发农产品产地直发7",@"【农家特产】大蒜5斤/10斤 干蒜头大蒜头蒜子批发农产品产地直发8",@"【农家特产】大蒜5斤/10斤 干蒜头大蒜头蒜子批发农产品产地直发9",@"【农家特产】大蒜5斤/10斤 干蒜头大蒜头蒜子批发农产品产地直发10"];
    self.imageNames = @[@"j1.jpg",@"j2.jpg",@"j3.jpg",@"j4.jpg",@"j5.jpg",@"j6.jpg",@"j7.jpg",@"j8.jpg",@"j9.jpg",@"j10.jpg"];
    self.priceNames =@[@"¥90",@"¥91",@"¥92",@"¥93",@"¥94",@"¥95",@"¥96",@"¥97",@"¥98",@"¥99"];
    
}

- (void)setlayout {
    
    
    self.tableView.sd_layout
    .leftSpaceToView(self.view, 0)
    .topSpaceToView(self.view, 0)
    .widthIs(Wi)
    .heightIs(MyTableViewHeight);
    
    
}

- (void)setupNavigationItems {
    
    /** 导航条左边的按钮 */
    //返回按钮
    UIButton *kfBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [kfBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    kfBtn.frame = CGRectMake(0, 0, 30, 30);
    [kfBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:kfBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    /** 搜索 */
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
    titleLabel.text = @"排行榜";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = FONT_EIGHTEEN;
    titleLabel.textColor = [UIColor colorWithHex:0x29b566];
    self.navigationItem.titleView = titleLabel;
    
    
    /** 搜索 */
    
    UIButton *searchButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-140, 30)];
    searchButton.backgroundColor = [UIColor colorWithHex:0xFFF1F1F1];
    searchButton.titleLabel.font = FONT_TWELVE;
    [searchButton addTarget:self action:@selector(search:) forControlEvents:UIControlEventTouchUpInside];
    [searchButton setTitleColor:[UIColor colorWithHex:0x999999] forState:UIControlStateNormal];
    [searchButton setTitle:@"排行榜" forState:UIControlStateNormal];
    searchButton.cornerRadius = 5;
    [searchButton setImage:[UIImage imageNamed:@"ss"] forState:UIControlStateNormal];
    self.navigationItem.titleView = searchButton;
    
    
    
    
}

#pragma mark - Action


/** 搜索 */
- (void)search:(UIButton *)btu {
    
    LLSearchViewController *vc = [[LLSearchViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}



- (void)backAction:(UIBarButtonItem *)item {
    [self.navigationController popViewControllerAnimated:YES];
}



#pragma mark - tableViewDelegate & tableViewDatasorce



//几个分区
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 10;
}

/** cell的高度 */

/** cell 自适应第二步 */
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    return [tableView cellHeightForIndexPath:indexPath model:self.modelsArray[indexPath.row] keyPath:@"model" cellClass:[AXNzscNztjSecondCell class] contentViewWidth:SCREEN_WIDTH];
    
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
    AXNzscNztjSecondCell *cell = [tableView dequeueReusableCellWithIdentifier:[AXNzscNztjSecondCell reuseID] forIndexPath:indexPath];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    cell.productImageView.image = [UIImage imageNamed:self.imageNames[indexPath.row]];
    cell.nameLabel.text = self.titleNames[indexPath.row];
    cell.priceLabel.text = self.priceNames[indexPath.row];
    
    return cell;
    
    
}




@end


